<style>
    .red {
        color: red;
    }
</style>
<input type="hidden" name="egid" value="{$reply['id']}"/>
<!--基本设置-->
<div class="panel panel-default">
    <div class="panel-heading">
        基本设置
    </div>
    <div class="panel-body">

        <div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 活动名称：</label>

            <div class="col-sm-9 col-xs-12">
                <input type="text" id="title" class="form-control span7"
                       placeholder="" name="title" value="{$reply['title']}">
            </div>
        </div>


        <div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span class='red'>*</span>活动开始时间：</label>

            <div class="col-sm-9 col-xs-12">
                {php echo tpl_form_field_date('starttime',$reply['starttime'],true)}
            </div>
        </div>

        <div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span class='red'>*</span>活动结束时间：</label>

            <div class="col-sm-9 col-xs-12">
                {php echo tpl_form_field_date('endtime',$reply['endtime'],true)}
            </div>
        </div>


        <div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span class='red'>*</span>关注引导图文介绍链接：</label>

            <div class="col-sm-9 col-xs-12">
                <input type="text" id="follow_url" class="form-control span7"
                       placeholder="" name="follow_url" value="{$reply['follow_url']}">
            </div>
        </div>

        <div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span class='red'>*</span>关注按钮文字：</label>

            <div class="col-sm-9 col-xs-12">
                <input type="text" id="follow_btn_name" class="form-control span7" placeholder="" name="follow_btn_name"
                       value="{if $reply['follow_btn_name']}{$reply['follow_btn_name']}{else}关注{/if}">
                <div class="help-block"></div>
            </div>
        </div>


        <div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span class='red'>*</span>关注接提示文字：</label>

            <div class="col-sm-9 col-xs-12">
                <textarea style="height: 60px;" name="follow_dlg_tip" class="form-control span7" cols="60">{if $reply['follow_dlg_tip']}{$reply['follow_dlg_tip']}{else}关注公众号后才能砸金蛋哦！{/if}</textarea>
            </div>
        </div>




        <div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span class='red'>*</span>每个用户每天砸金蛋次数：</label>

            <div class="col-sm-9 col-xs-12">
                <input type="text" id="day_count" class="form-control span7" placeholder="" name="day_count"
                       value="{if $reply['day_count']}{$reply['day_count']}{else}1{/if}">
                <div class="help-block"></div>
            </div>
        </div>


        <div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span class='red'>*</span>每个用户中奖次数限制：</label>

            <div class="col-sm-9 col-xs-12">
                <input type="text" id="prize_limit" class="form-control span7" placeholder="" name="prize_limit"
                       value="{if $reply['prize_limit']}{$reply['prize_limit']}{else}0{/if}">
                <div class="help-block"></div>
            </div>
        </div>

        <!--<div class="form-group">-->
            <!--<label class="col-xs-12 col-sm-3 col-md-2 control-label"><span class='red'>*</span>滚动显示中奖条数</label>-->

            <!--<div class="col-sm-9 col-xs-12">-->
                <!--<input type="number" id="randking_count" class="form-control span7"-->
                       <!--placeholder="" name="randking_count" value="{$reply['randking_count']}">-->
            <!--</div>-->
        <!--</div>-->

        <div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span class='red'>*</span>兑奖密码：</label>
            <div class="col-sm-9 col-xs-12">
                <input type="password" id="dpassword" class="form-control span7" placeholder="" name="dpassword"
                       value="{$reply['dpassword']}">
                <div class="help-block"></div>
            </div>
        </div>


        <div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span class='red'>*</span>版权</label>

            <div class="col-sm-9 col-xs-12">
                <input type="text" id="copyright" class="form-control span7"
                       placeholder="" name="copyright" value="{$reply['copyright']}">
            </div>
        </div>

        <div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span class='red'>*</span>宣传图片:</label>

            <div class="col-sm-9 col-xs-12">
                {php echo tpl_form_field_image('banner_bg',$reply['banner_bg'],MonUtil::defaultImg(MonUtil::$IMG_BANNER_BG));}
                建议宽*高(640*714)
            </div>
        </div>


        <div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span class='red'>*</span>背景音乐:</label>

            <div class="col-sm-9 col-xs-12">
                {php echo tpl_form_field_audio('music', $reply['music']);}
                <div class="help-block">不填写会是默认音乐</div>
            </div>
        </div>


        <div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span class='red'>*</span>主题背景图:</label>

            <div class="col-sm-9 col-xs-12">
                {php echo tpl_form_field_image('bg_img',$reply['bg_img'],MonUtil::defaultImg(MonUtil::$IMG_BG));}
                建议宽*高(541*189)
            </div>
        </div>



        <div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span class='red'>*</span>分享引导:</label>

            <div class="col-sm-9 col-xs-12">
                {php echo tpl_form_field_image('share_bg',$reply['share_bg'],MonUtil::defaultImg(MonUtil::$IMG_SHARE_BG));}
                建议宽*高(330*228)
            </div>
        </div>


        <div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span class='red'>*</span>活动说明:</label>

            <div class="col-sm-9 col-xs-12">
                  <textarea style="height: 60px;" id="intro" name="intro"
                            class="form-control span7" cols="60">{$reply['intro']}</textarea>
            </div>
        </div>


        <div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span class='red'>*</span>分享奖励设置：</label>
            <div class="help-block">例如： 填写填写 3、1  表示:每个用户每天分享，前3次分可以得到奖励机会，每次奖励一次砸金蛋机会，后面再分享无效, 不会得到奖励机会。</div>

            <div class="col-sm-9" style="margin-top:5px;">

                <div class="checkbox  col-sm-1">

                    <label>
                        <input type="checkbox" id="share_enable" name="share_enable" {if $reply['share_enable']==1}checked="checked"{/if} value="{$reply['share_enable']}" >启用


                    </label>
                </div>

                <div class="input-group col-sm-4" style="float:left">
                    <span class="input-group-addon">每天奖励分享</span>
                    <input type="text" class="form-control span1" name="share_times" value="{$reply['share_times']}">
                    <span class="input-group-addon">次</span>

                </div>
                <div class="input-group col-sm-4" style="float:left">
                    <span class="input-group-addon">每次分享奖励抽奖就会</span>
                    <input type="text" class="form-control span1" name="share_award_count" value="{$reply['share_award_count']}">
                    <span class="input-group-addon">次</span>

                </div>




            </div>


        </div>


    </div>

</div>






<!--奖品设置--->
<div class="panel panel-default">
    <div class="panel-heading">
        奖品设置
    </div>
    <div class="panel-body">

        <div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>

            <div class="col-sm-9 col-xs-12">
                <span class="label label-danger" id="p_text">未中奖概率:万分之</span>
                <table class="table table-hover">
                    <thead>
                    <tr>
                        <th width="60px">排序</th>
                        <th width="100px">奖品级别</th>
                        <th width="100px">奖品名称</th>
                        <th width="80px">奖品数量</th>
                        <th width="80px">类型<font color="red">(奖品是积分时需要填写积分)</font></th>
                        <th width="80px">积分</th>
                        <th width="80px">中奖概率</th>
                        <th width="150px">奖品图片(大小120*120)</th>
                        <th width="200px">操作</th>
                    </tr>
                    </thead>

                    <tbody class="prize-items">


                    {loop $prizes $pr}
                    <tr>
                        <td><input type="text" class="form-control" name="display_orders[]" value="{$pr['display_order']}"/></td>
                        <td><input type="text" class="form-control" name="plevels[]" value="{$pr['plevel']}"/></td>
                        <td><input type="text" class="form-control" name="pnames[]" value="{$pr['pname']}"/></td>
                        <td><input type="text" class="form-control" name="pcounts[]" value="{$pr['pcount']}"/></td>
                        <td>
                            <select name="ptypes[]" >
                                <option value="1" {if $pr['ptype']==1}selected ='selected'{/if} >实物</option>
                                <option value="2" {if $pr['ptype']==2}selected ='selected'{/if} >积分</option>
                             </select>
                        </td>
                        <td><input type="text" class="form-control" name="jfs[]" value="{$pr['jf']}"/></td>

                        <td><input type="text" class="form-control" name="pbs[]" value="{$pr['pb']}" onkeyup="pChange();"/></td>
                        <td>
                            <div id="img_div">
                                <img src="{if $pr['pimg']}{$_W['attachurl']}{$pr['pimg']}{/if}"
                                     style="max-width: 80px; max-height: 80px;">
                                <input name="pimgs[]" type="hidden" value="{$pr['pimg']}" />
                            </div>
                        </td>

                        <td><input name="pids[]" type="hidden" value="{$pr['id']}"/><span onclick="upimg(this)"
                                                                                          class="btn btn-primary"><i
                                class="fa fa-plus"></i>上传图片</span>&nbsp;<a href="javascript:;" onclick="removePrize(this)"><i class="glyphicon glyphicon-remove"></i> 删除</a></td>

                    </tr>

                    {/loop}


                    </tbody>

                </table>
            </div>
        </div>


        <div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>

            <div class="col-sm-9 col-xs-12">
                <a href="javascript:void(0);" onclick="addPrize();"><i class="gglyphicon glyphicon-plus" title="添加奖品"></i>添加奖品</a>
            </div>
        </div>


    </div>

</div>


<!--图文样式设置-->
<div class="panel panel-default">
    <div class="panel-heading">
        图文设置
    </div>
    <div class="panel-body">

        <div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span class='red'>*</span>图文标题：</label>

            <div class="col-sm-9 col-xs-12">
                <input type="text" id="new_title" class="form-control span7" placeholder="" name="new_title"
                       value="{$reply['new_title']}">

            </div>
        </div>


        <div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span class='red'>*</span>图文 图标：</label>

            <div class="col-sm-9 col-xs-12">
                {php echo tpl_form_field_image('new_icon',$reply['new_icon']);}
            </div>
        </div>

        <div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span class='red'>*</span>图文描述：</label>

            <div class="col-sm-9 col-xs-12">
			<textarea style="height: 60px;" name="new_content"
                      class="form-control span7" cols="60">{$reply['new_content']}</textarea>
            </div>
        </div>


    </div>
</div>

<!--分享设置-->
<div class="panel panel-default">
    <div class="panel-heading">
        分享设置
    </div>
    <div class="panel-body">

        <div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span class='red'>*</span>分享标题：</label>

            <div class="col-sm-9 col-xs-12">
                <input type="text" id="share_title" class="form-control span7" placeholder="" name="share_title"
                       value="{$reply['share_title']}">
                <div class="help-block"></div>
            </div>
        </div>


        <div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span class='red'>*</span>分享图标：</label>

            <div class="col-sm-9 col-xs-12">
                {php echo tpl_form_field_image('share_icon',$reply['share_icon']);}
            </div>
        </div>

        <div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span class='red'>*</span>分享描述：</label>

            <div class="col-sm-9 col-xs-12">
			<textarea style="height: 60px;" name="share_content"
                      class="form-control span7" cols="60">{$reply['share_content']}</textarea>
                <div class="help-block"></div>
            </div>
        </div>


    </div>
</div>
<script>

    $(function(){

        $("#share_enable").click(function(){



            if($(this).get(0).checked){

                $(this).val(1);
            }else{
                $(this).val(0);
            }


        });
        pChange();

    });


    require(['jquery', 'util'], function ($, u) {
        $(function () {
            u.editor($('#intro')[0]);
        });
    });

/**
 * 添加奖品
 */
function addPrize() {
    var index = $(".prize-items tr").length + 1;
    var html = "<tr>";
    html += '<td><input type="text" class="form-control" name="display_orders[]"  value="' + index + '"/></td>';
    html += '<td><input type="text" class="form-control" name="plevels[]"  value=""/></td>';
    html += '<td><input type="text" class="form-control" name="pnames[]"  value=""/></td>';
    html += '<td><input type="text" class="form-control" name="pcounts[]"  value="1"/></td>';
    html += '<td><select name="ptypes[]"><option value="1" >实物</option><option value="2" >积分</option></select></td>';
    html += '<td><input type="text" class="form-control" name="jfs[]" value="0"/></td>';
    html += '<td><input type="text" class="form-control" name="pbs[]"  value="0" onkeyup="pChange();" /></td>';
    html += '<td><div id="img_div"></div></td>';

    html += '<td> <input  name="pids[]" type="hidden" value="" /><span onclick="upimg(this)" class="btn btn-primary"><i class="fa fa-plus"></i>上传图片</span>&nbsp;<a href="javascript:;" onclick="removePrize(this)" ><i class="glyphicon glyphicon-remove"></i> 删除</a></td>';

    html += "</tr>";

    $(".prize-items").append(html);

}

    function pChange(){
        var totalP=0;
        $(".prize-items tr input[name='pbs[]']").each(function () {
            var vp=$(this).val();
            if(!isNaN(vp)){
                totalP+=parseInt(vp);
            }

        });
        $("#p_text").html("未中奖概率:万分之"+(10000-totalP)+"");
    }

    function upimg(obj) {

        require(['jquery', 'util'], function ($, util) {

            util.image('', function (data) {
                $(obj).parent().parent().find('#img_div').html('<img src="' + data['url'] + '" style="max-width: 80px; max-height: 80px;"><input name="pimgs[]" type="hidden" value="' + data['filename'] + '" />');

            });

        });


    }

    function removePrize(obj) {


        var pid= $(obj).parent().parent().find("input[name='pids[]']").val();

        if(pid!=""){

            $.post("{php echo $this->createWebUrl('DeletePrize')}",{"pid":pid},function(res){


                if(res.code==200){
                    $(obj).parent().parent().remove();
                    pChange();

                }else{

                    alert("该奖品有用户中奖记录不能删除！请删除该奖品的用户中奖记录后再删除此奖品！");
                }


            },'json');
        }else{

            $(obj).parent().parent().remove();
            pChange();
        }
    }

</script>

